package com.pzhu.filter;

import com.pzhu.controller.impl.BookControllerImpl;
import com.pzhu.pojo.Book;

import javax.servlet.*;
import java.io.IOException;

public class UpdateBookFilter implements Filter {
    BookControllerImpl bookController = new BookControllerImpl();
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("updateBookFilter 执行");
        long id = Long.parseLong(servletRequest.getParameter("id"));
        Book book = bookController.selectBook(id);
        System.out.println(book.getName());
        servletRequest.setAttribute("book",book);
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
